package com.ias.agdis_r.manager;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.Log;

import com.ias.agdis_r.R;
import com.ias.agdis_r.bean.document.Document;
import com.ias.agdis_r.bean.other.GpsInfoBean;
import com.ias.agdis_r.bean.other.IQRYInfoBean;
import com.ias.agdis_r.module.MessageModel;
import com.ias.agdis_r.module.ParameterModel;
import com.ias.agdis_r.util.S;
import com.ias.agdis_r.util.ServiceLabelUtil;
import com.ias.agdis_r.util.TestUtil;

/**
 * 信息管理类
 * 
 * @author wanghu
 * 
 */
@SuppressLint("SimpleDateFormat")
public class MessageManager {

	private static MessageManager instance = null;// 单例的消息管理器
	private String lastSGOCMessage = null;// 最后发送的心跳消息
	private String lastIQRYMessage = null;// 最后发送的IQRY消息

	private String lastGWSMMessage = null;// 最后一次发送的信息
	private String lastBDWIMessage = null;// 最后一次发送（回复）的生产通告信息
	private String lastSearchFlightMessage = null;// 最后一次发送的登录信息
	private String lastGpsMessage = null;// 最后一次发送的Gps信息
	private String lastJobWorkingPhraseMessage = null;// 最后发送的常用工作短语信息
	private String lastTaskWorkingPhraseMessage = null;// 最后发送的任务相关工作短语信息
	private String lastLogoutMessage = null;// 最后一次发送的注销信息
	private String lastLogonMessage = null;// 最后一次发送的登录信息
	private String lastRecLogonMessage = null;// 最后一次接收的登录信息
	private String lastApplyFlightTaskMessage = null;// 最后一次发送的申请任务信息
	private String lastConfirmRefreshMsg = null;//最后一次发送确认任务更新的信息  add by zhangsc

	private String lastAcceptOrRefuseMessage = null;// // 最后一次发送的接受或拒绝任务信息
	private String lastGroupMessage = null;// 最后一次发送的获取同组员工信息
	private String lastScanMessage = null;// 最后一次发送的上报扫描结果
	private String lastTaskMessage = null;
	private String lastQQRYMessage = "";
	private String lastMonitorMessage = null;
	private String lastRemindMsg = null;
	private String lastTRBDMessage = null;//
	private String lastLockMsg = null; //锁定机位消息
	private String lastSubMsg = null; //航班订阅信息
	private String lastRMK = null;

	private Context context = DataBaseManager.getInstance().getContext();
	/**
	 * 单例模式
	 * 
	 * @return
	 */
	public static MessageManager getInstance() {
		if (instance == null) {
			instance = new MessageManager();
		}
		return instance;
	}

	/**
	 * 生成要发送到服务器的信息字符串
	 * 
	 * @param messageno
	 *            消息号(7位数字前2位)
	 * @param mt
	 *            消息头(模块的标识)
	 * @param colstr
	 *            字段数组(每个值都是 字段名+字段值)
	 * @return
	 */
	private String getMessage(String messageno, String mt, List<String> colstr) {
		if (S.isEmpty(messageno) || S.isEmpty(mt)) {
			return "";
		}

		StringBuffer buffer = new StringBuffer(5000);
		StringBuffer bufferresult = new StringBuffer(5000);

		bufferresult.append(MessageModel.BEGIN);

		buffer.append(messageno);
		buffer.append(S.getAutoIncrementNum());
		buffer.append(",");
		buffer.append(mt);
		buffer.append(",");
		//SSN值修改为IMEI号
		buffer.append(S.contact(MessageModel.SSN, ParameterModel.IMEI_ID));
		
		String sEnb = JavaBeanManager.getInstance().getUserinfo().getEnb();
		if(S.isNotEmpty(sEnb)) {
			colstr.add(S.contact(MessageModel.SEN, sEnb));
		}
		
		if (colstr != null) {
			for (String s : colstr) {
				buffer.append(",");
				buffer.append(s);
			}
		}
		buffer.append(",");

		String checkcode = S.getCheckCode(buffer.toString());

		bufferresult.append(buffer);
		bufferresult.append(checkcode);
		bufferresult.append(MessageModel.END);
		return bufferresult.toString();
	}
	
	/**
	 * 生成要发送到服务器的信息字符串
	 * 
	 * @param messageno
	 *            消息号(7位数字前2位)
	 * @param mt
	 *            消息头(模块的标识)
	 * @param colstr
	 *            字段数组(每个值都是 字段名+字段值)
	 * @return
	 */
	private String getTestMessage(String messageno, String mt, List<String> colstr) {
		if (S.isEmpty(messageno) || S.isEmpty(mt)) {
			return "";
		}

		StringBuffer buffer = new StringBuffer(5000);
		StringBuffer bufferresult = new StringBuffer(5000);

		bufferresult.append(MessageModel.BEGIN);

		buffer.append(messageno);
		buffer.append("00000");
		buffer.append(",");
		buffer.append(mt);
		buffer.append(",");
		buffer.append(S.contact(MessageModel.SSN, ParameterModel.IMEI_ID));
		
		String sEnb = JavaBeanManager.getInstance().getUserinfo().getEnb();
		if(S.isNotEmpty(sEnb)) {
			colstr.add(S.contact(MessageModel.SEN, sEnb));
		}
		
		if (colstr != null) {
			for (String s : colstr) {
				buffer.append(",");
				buffer.append(s);
			}
		}
		buffer.append(",");

		String checkcode = S.getCheckCode(buffer.toString());

		bufferresult.append(buffer);
		bufferresult.append(checkcode);
		bufferresult.append(MessageModel.END);
		return bufferresult.toString();
	}
	
	private String getRiliReloMessage(String messageno, String mt, List<String> colstr) {
		if (S.isEmpty(messageno) || S.isEmpty(mt)) {
			return "";
		}

		StringBuffer buffer = new StringBuffer(5000);
		StringBuffer bufferresult = new StringBuffer(5000);

		bufferresult.append(MessageModel.BEGIN);

		buffer.append(messageno);
		buffer.append(S.getAutoIncrementNum());
		buffer.append(",");
		buffer.append(mt);
		buffer.append(",");
		buffer.append(S.contact(MessageModel.SSN, ParameterModel.IMEI_ID));
		if (colstr != null) {
			for (String s : colstr) {
				buffer.append(",");
				buffer.append(s);
			}
		}
		buffer.append(",");

		String checkcode = S.getCheckCode(buffer.toString());

		bufferresult.append(buffer);
		bufferresult.append(checkcode);
		bufferresult.append(MessageModel.END);
		return bufferresult.toString();
	}

	/**
	 * 主动申请单据信息
	 * 
	 * @param TNB
	 * @param IDX
	 * @return
	 */
	public String getApplyDanJuIQRYMessage(String TNB, String IDX, String DID) {
		String messageno = MessageModel.UP_AKANSWER;
		String mt = MessageModel.IQRY;
		List<String> colstr = new ArrayList<String>();
		colstr.add(MessageModel.FLG7);
		colstr.add(S.contact(MessageModel.TNB, TNB));
		colstr.add(S.contact(MessageModel.DID, DID));
		colstr.add(S.contact(MessageModel.strTxtValue[MessageModel.nIDX], IDX));// 去信息里面的值
		lastIQRYMessage = getMessage(messageno, mt, colstr);
		return lastIQRYMessage;
	}

	/**
	 * 上报打印单据成功
	 * @param fke
	 * @param document
	 * @return
	 */
	public String getBLPTMessage(String fke,Document document){

		String messageno = MessageModel.UP_RPANSWER;
		String mt = MessageModel.BLPT;
		List<String> colstr = new ArrayList<String>();
		colstr.add(S.contact(MessageModel.STM, S.getNowTime()));
		colstr.add(S.contact(MessageModel.FKE, fke));
		colstr.add(S.contact(MessageModel.BTP, document.getBTP()));
		colstr.add(S.contact(MessageModel.BKE, document.getBKE()));
		colstr.add(S.contact(MessageModel.BNO, document.getBNO()));
		String msessage = getMessage(messageno, mt, colstr);
		return msessage;
	}
	
	/**
	 * 获取单据文本内容
	 * @param fke
	 * @param document
	 * @return
	 */
	public String getBLDTMessage(String fke,Document document){

		String messageno = MessageModel.UP_RPANSWER;
		String mt = MessageModel.BLDT;
		List<String> colstr = new ArrayList<String>();
		colstr.add(S.contact(MessageModel.STM, S.getNowTime()));
		colstr.add(S.contact(MessageModel.FKE, fke));
		colstr.add(S.contact(MessageModel.BTP, document.getBTP()));
		colstr.add(S.contact(MessageModel.BKE, document.getBKE()));
		colstr.add(S.contact(MessageModel.BNO, document.getBNO()));
		String msessage = getMessage(messageno, mt, colstr);
		return msessage;
	}
	
	/**
	 * 获取单据信息摘要信息
	 * @param fke
	 * @param document
	 * @return
	 */
	public String getBLRQMessage(String fke){

		String messageno = MessageModel.UP_RPANSWER;
		String mt = MessageModel.BLRQ;
		List<String> colstr = new ArrayList<String>();
		colstr.add(S.contact(MessageModel.STM, S.getNowTime()));
		colstr.add(S.contact(MessageModel.FKE, fke));
		String msessage = getMessage(messageno, mt, colstr);
		return msessage;
	}

	
	/**申请单据信息
	 * 
	 * @author zhangsc
	 * @return
	 */
	public String getApplyDanJuQQRYMessage(String QRY,String FKE,String BTP)
	{
		String messageno = MessageModel.UP_RPANSWER;
		String mt = MessageModel.QQRY;
		List<String> colstr = new ArrayList<String>();
		colstr.add(S.contact(MessageModel.STM, S.getNowTime()));
		colstr.add(S.contact(MessageModel.QRY, QRY));
		colstr.add(S.contact(MessageModel.FKE, FKE));
		colstr.add(S.contact(MessageModel.BTP, BTP));
		lastQQRYMessage = getMessage(messageno, mt, colstr);
		return lastQQRYMessage;
	}
	
	public String getNormalIQRYMessage(){

		String messageno;
		String mt;

		String addedString = "";
		List<String> colstr;
		messageno = MessageModel.UP_AKANSWER;
		mt = MessageModel.IQRY;
		colstr = new ArrayList<String>();
		colstr.add(S.contact(MessageModel.STM, S.getNowTime()));
		colstr.add(MessageModel.FLG1);
		
		if (S.isNotEmpty(addedString)) {
			String[] sTmpArray = addedString.split(",");
			for (int m = 0; m < sTmpArray.length; m++) {
				colstr.add(sTmpArray[m]);
			}
		}

		lastIQRYMessage = getMessage(messageno, mt, colstr);
		
		Log.i("GWSM_Msg", "getNormalIQRYMessage:"+lastIQRYMessage);
		return lastIQRYMessage;
	}

	/**
	 * 获取GPS信息
	 */
	public String getGpsMessage(String... message) {
		String VNB = JavaBeanManager.getInstance().getUserinfo().getVnb();
		String messageno = MessageModel.UP_NOANSWER;
		String mt = MessageModel.GGDS;
		List<String> colstr = new ArrayList<String>();
		if (S.isNotEmpty(VNB)) {
			colstr.add(MessageModel.VNB + VNB);
		}
		colstr.add(MessageModel.LGT + message[0]);
		colstr.add(MessageModel.LTT + message[1]);
		colstr.add(MessageModel.SPD + message[2]);
		colstr.add(MessageModel.DRT + message[3]);
		colstr.add(MessageModel.SDT + message[4]);
		colstr.add(MessageModel.ENB + S.valueOf(JavaBeanManager.getInstance().getUserinfo().getEnb()));

		lastGpsMessage = getMessage(messageno, mt, colstr);

		return lastGpsMessage;
	}

	/**
	 * 通用AK应答
	 * 
	 * @param message
	 */
	public String getAKAnswer(String message) {
		String messageno = MessageModel.UP_NOANSWER_ANSWER;
		String mt = MessageModel.SGRP;
		List<String> colstr = new ArrayList<String>();
		String rmt = S.mySubString(message, 10, 14);
		if (S.isNotEmpty(rmt)) {
			colstr.add(MessageModel.RMT + rmt);
		} else {
			colstr.add(MessageModel.RMT);
		}
		String rms = S.mySubString(message, 2, 9);
		if (S.isNotEmpty(rms)) {
			colstr.add(MessageModel.RMS + rms);
		} else {
			colstr.add(MessageModel.RMS);
		}
		return getMessage(messageno, mt, colstr);
	}

	/**
	 * 查询航班信息发送
	 */
	public String getSearchFlightMessage(String type,String searchTxt, String page, int num, String dir, String stime, String etime,String ifa,String aod) {
		String messageno = MessageModel.UP_RPANSWER;
		String mt = MessageModel.QFIQ;
		List<String> colstr = new ArrayList<String>();

		colstr.add(MessageModel.NUM + num);
		colstr.add(MessageModel.FLIGHT_PAGE + page);
		colstr.add(MessageModel.FLIGHT_PAGE_DIR + dir);
		
		if(S.isNotEmpty(type))
		{
			searchTxt = "<!TX<" + S.getCDATA(searchTxt) +">!>";
			colstr.add(type + searchTxt);
		}
		if(S.isNotEmpty(stime)){
			colstr.add(MessageModel.FTM+stime);
		}
		if(S.isNotEmpty(etime)){
			colstr.add(MessageModel.TTM+etime);
		}
		//代理航班标记
		if(S.isNotEmpty(ifa))
		{
			colstr.add(MessageModel.IFA+ifa);
		}
		
		if(S.isNotEmpty(aod))
		{
			colstr.add(MessageModel.AOD+aod);
		}
		lastSearchFlightMessage = getMessage(messageno, mt, colstr);

		return lastSearchFlightMessage;
	}

	/**
	 * 发送获取最新情况反映(或生产通告)数据信息 type: 10 情况反映 99 生产通告
	 */
	public String getGetWorkingPhraseInfo(String txt, String type, String tnb,
			String fke, String tgn,String mid) {

		String messageno = MessageModel.UP_AKANSWER;
		String mt = MessageModel.GWSM;
		txt = S.getCDATA(txt);
		List<String> colstr = new ArrayList<String>();
		colstr.add(MessageModel.MTI + type);
		colstr.add(MessageModel.TXL + S.getStringLen(txt));
		colstr.add(MessageModel.TXT + txt);	
		colstr.add(MessageModel.MID + mid);	

		if (S.isNotEmpty(tnb)) {
			colstr.add(MessageModel.TNB + tnb);
		}

		if (S.isNotEmpty(fke)) {
			colstr.add(MessageModel.strTxtValue[MessageModel.nFKE] + fke);
		}
		//add by huzedong
		if (S.isNotEmpty(tgn)) {
			colstr.add(MessageModel.TGN + tgn);
		}
		
		String result = "";
		if (type.equals("02") || type.equals("10")) {
			lastGWSMMessage = getMessage(messageno, mt, colstr);
			result = lastGWSMMessage;
		} else if (type.equals("99")) {
			lastBDWIMessage = getMessage(messageno, mt, colstr);
			result = lastBDWIMessage;
		}

		return result;
	}
	
	/**
	 * 发送获取作业记录数据信息
	 */	
	public String getQQRYMessage(String _sFke, String _sQry) {

		String messageno = MessageModel.UP_RPANSWER;
		String mt = MessageModel.QQRY;

		List<String> colstr = new ArrayList<String>();
		colstr.add(S.contact(MessageModel.STM, S.getNowTime()));
		if (S.isNotEmpty(_sFke)) {
			colstr.add(MessageModel.strTxtValue[MessageModel.nFKE] + _sFke);
		}
		colstr.add(S.contact(MessageModel.QRY, _sQry));
		lastQQRYMessage = getMessage(messageno, mt, colstr);

		return lastQQRYMessage;
	}

	// 获取只包含FLG4的特殊IQRY信息
	public String getFLG4IQRYMessage(String _sIdx) {
		String messageno = MessageModel.UP_AKANSWER;
		String mt = MessageModel.IQRY;
		List<String> colstr = new ArrayList<String>();
		
		if (_sIdx == null) {
			colstr.add(MessageModel.FLG4);
			colstr.add(MessageModel.strTxtValue[MessageModel.nIDX]);
		}else
		{
			colstr.add(MessageModel.FLG4);
			colstr.add(S.contact(MessageModel.strTxtValue[MessageModel.nIDX],_sIdx));
		}
		
		lastIQRYMessage = getMessage(messageno, mt, colstr);
		return lastIQRYMessage;
	}
	
	/**
	 * 给服务器发送注销请求
	 */
	public String getLogoutMessage() {
		// 获取要发送的注销信息
		String messageno = MessageModel.UP_AKANSWER;
		String mt = MessageModel.RELO;

		List<String> colstr = new ArrayList<String>();
		colstr.add(S.contact(MessageModel.SEN, JavaBeanManager.getInstance()
				.getUserinfo().getEnb()));

		lastLogoutMessage = getRiliReloMessage(messageno, mt, colstr);

		return lastLogoutMessage;
	}

	/**
	 * 给服务器发送登录信息
	 */
	public String getLoginMessage(String txt_userno, String txt_password,
			boolean isQiangXing) {

		// ServiceManage.getInstance().SendSINI();

		// 获取要发送的登录信息
		String messageno = MessageModel.UP_RPANSWER;
		String mt = MessageModel.RELI;
		@SuppressWarnings("unused")
		int strLen = 4;
		if (isQiangXing) {
			strLen = 5;
		}
		List<String> colstr = new ArrayList<String>();
		txt_userno = S.getCDATA(txt_userno);
		txt_password = S.getCDATA(txt_password);
		colstr.add(S.contact(MessageModel.ENB, txt_userno));
		colstr.add(S.contact(MessageModel.PWD, txt_password));
		colstr.add(S.contact(MessageModel.IMEI, ParameterModel.IMEI_ID));
		colstr.add(S.contact(MessageModel.MSV, ParameterModel.AP_VER_ID));

		if (isQiangXing) {
			colstr.add(S.contact(MessageModel.FLG, "Y"));
		} else {
			colstr.add(S.contact(MessageModel.FLG, "N"));
		}

		lastLogonMessage = getRiliReloMessage(messageno, mt, colstr);

		return lastLogonMessage;
	}

	// 获取只包含FLG3的特殊IQRY信息
	public String getFLG3IQRYMessage(String IDX) {

		String messageno = MessageModel.UP_AKANSWER;
		String mt = MessageModel.IQRY;
		List<String> colstr = new ArrayList<String>();

		colstr.add(MessageModel.FLG3);

		if (S.isNotEmpty(IDX)) {
			colstr.add(MessageModel.strTxtValue[MessageModel.nIDX] + IDX);
		} else {
			colstr.add(MessageModel.strTxtValue[MessageModel.nIDX]);
		}

		lastIQRYMessage = getMessage(messageno, mt, colstr);
		return lastIQRYMessage;
	}

	// 获取只包含FLG7的特殊IQRY信息
	public String getFLG7IQRYMessage(String _sTNB, String _sIDX) {

		String messageno = MessageModel.UP_AKANSWER;
		String mt = MessageModel.IQRY;
		List<String> colstr = new ArrayList<String>();

		colstr.add(MessageModel.FLG7);
		colstr.add(S.contact(MessageModel.TNB, _sTNB));
		colstr.add(S.contact(MessageModel.strTxtValue[MessageModel.nIDX], _sIDX));
		
		lastIQRYMessage = getMessage(messageno, mt, colstr);
		return lastIQRYMessage;
	}
	
	/**
	 * 发送申请任务消息
	 */
	public String getApplyTaskMessage(String _sRrp, String flight_id) {
		String messageno = MessageModel.UP_RPANSWER;
		String mt = MessageModel.TTRQ;
		List<String> colstr = new ArrayList<String>();
		colstr.add(S.contact(MessageModel.RTP, _sRrp));
		colstr.add(S.contact(MessageModel.strTxtValue[MessageModel.nFKE], flight_id));
		lastApplyFlightTaskMessage = getMessage(messageno, mt, colstr);
		return lastApplyFlightTaskMessage;
	}
	
	/**
	 * 确认短语消息
	 */
	public String confirmGwsmMsg(String _sTgn) {
		String sConfirmMsg ="";
		String messageno = MessageModel.UP_AKANSWER;
		String mt = MessageModel.GWRP;
		//确认消息取系统时间
		SimpleDateFormat adfTime = new SimpleDateFormat("HHmm");
		Date date = new Date();
		String sdt = adfTime.format(date);
		
		List<String> colstr = new ArrayList<String>();
		colstr.add(S.contact(MessageModel.TGN, _sTgn));
		colstr.add(S.contact(MessageModel.TST, "R"));
		colstr.add(S.contact(MessageModel.SDT, sdt));
		sConfirmMsg = getMessage(messageno, mt, colstr);
		return sConfirmMsg;
	}	
	
	/**
	 * 获取任务更新返回的消息
	 * 
	 * @author zhangsc
	 */
	public String comfirmRefreshMsg(String _sTnb, String _sUci) {
		
		String messageno = MessageModel.UP_RPANSWER;
		String mt = MessageModel.TURP;
		
		//确认消息取系统时间
		SimpleDateFormat adfTime = new SimpleDateFormat("HHmm");
		Date date = new Date();
		String sdt = adfTime.format(date);
		List<String> colstr = new ArrayList<String>();
		colstr.add(S.contact(MessageModel.TNB, _sTnb));
		colstr.add(S.contact(MessageModel.UCI, _sUci));
		colstr.add(S.contact(MessageModel.TST, "R"));
		colstr.add(S.contact(MessageModel.SDT, sdt));
		
		lastConfirmRefreshMsg = getMessage(messageno, mt, colstr);
		return lastConfirmRefreshMsg;
	}
	
	/**
	 * 获取心跳信息
	 * 
	 * @return
	 */
	public String getSGOCMessage() {
		// 获取要发送的心跳信息
		String messageno = MessageModel.UP_AKANSWER;
		String mt = MessageModel.SGOC;
		
		List<String> colstr = new ArrayList<String>();
		
		if((TestUtil.send_sgoc_count%TestUtil.send_cpu_interval)==0)
		{
			colstr.add(S.contact(TestUtil.TXT, S.valueOf(TestUtil.cpu_info)));
		}
		// 心跳信息
		lastSGOCMessage = getMessage(messageno, mt, colstr);
		// 心跳信息
		//lastSGOCMessage = getMessage(messageno, mt, null);
		return lastSGOCMessage;
	}

	/**
	 * 获取测试心跳信息
	 * 
	 * @return
	 */
	public String getTestSGOCMessage(int tag,String cct,String lct,String lpp,String txt) {
		// 获取要发送的心跳信息
		String messageno = MessageModel.UP_NOANSWER;
		String mt = MessageModel.SGOC;
		
		List<String> colstr = new ArrayList<String>();


		colstr.add(S.contact(TestUtil.TAG, S.valueOf(tag)));
		colstr.add(S.contact(TestUtil.CCT, S.valueOf(cct)));
		colstr.add(S.contact(TestUtil.LCT, S.valueOf(lct)));
		colstr.add(S.contact(TestUtil.LPP, S.valueOf(lpp).replaceAll(",", "|")));
		colstr.add(S.contact(TestUtil.TXT, S.valueOf(txt)));
		// 心跳信息
		lastSGOCMessage = getTestMessage(messageno, mt, colstr);
		// 心跳信息
		//lastSGOCMessage = getMessage(messageno, mt, null);
		return lastSGOCMessage;
	}
	/**
	 * 获取上报的卸货单信息
	 * **/
	public String getScanMessage(String txt, String tnb, String fke) {

		String messageno = MessageModel.UP_RPANSWER;
		String mt = MessageModel.TDTS;
		SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
		SimpleDateFormat format1 = new SimpleDateFormat("HHmm");
		Date date = new Date();
		String stm = format.format(date);
		List<String> colstr = new ArrayList<String>();

		colstr.add(S.contact(MessageModel.STM, stm));
		colstr.add(S.contact(MessageModel.TNB, tnb));
		colstr.add(S.contact(MessageModel.strTxtValue[MessageModel.nFKE], fke));
		colstr.add(S.contact(MessageModel.DID, "CG_ULDLIST"));
		colstr.add(S.contact(MessageModel.SDT, format1.format(date)));
		colstr.add(S.contact(MessageModel.TXL, S.getStringLen(txt)));
		colstr.add(S.contact(MessageModel.TXT, txt));

		lastScanMessage = getMessage(messageno, mt, colstr);

		return lastScanMessage;
	}
	
	/**
	 * 获取需要提交的货物运单信息
	 * **/
	public String getCargoYundanMessage(String txt,String fke) {
		
		String messageno = MessageModel.UP_RPANSWER;
		String mt = MessageModel.BDTS;
		SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
		SimpleDateFormat format1 = new SimpleDateFormat("HHmm");
		Date date = new Date();
		String stm = format.format(date);
		List<String> colstr = new ArrayList<String>();

		colstr.add(S.contact(MessageModel.STM, stm));
		colstr.add(S.contact(MessageModel.FKE, fke));
		colstr.add(S.contact(MessageModel.DID, "CG_MODCN"));
		colstr.add(S.contact(MessageModel.SDT, format1.format(date)));
		colstr.add(S.contact(MessageModel.TXL, S.getStringLen(txt)));
		colstr.add(S.contact(MessageModel.TXT, txt));

		lastScanMessage = getMessage(messageno, mt, colstr);
		
		return lastScanMessage;
	}
	/**
	 * 获取拖回扫描的信息
	 * **/
	public String getTuoHuiMessage(String txt) {

		String messageno = MessageModel.UP_RPANSWER;
		String mt = MessageModel.BDTS;
		SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
		SimpleDateFormat format1 = new SimpleDateFormat("HHmm");
		Date date = new Date();
		String stm = format.format(date);
		List<String> colstr = new ArrayList<String>();

		colstr.add(S.contact(MessageModel.STM, stm));
		colstr.add(S.contact(MessageModel.DID, "CG_INHTACM"));
		colstr.add(S.contact(MessageModel.SDT, format1.format(date)));
		colstr.add(S.contact(MessageModel.TXL, S.getStringLen(txt)));
		colstr.add(S.contact(MessageModel.TXT, txt));

		lastScanMessage = getMessage(messageno, mt, colstr);

		return lastScanMessage;
	}
	
	/**
	 * 获取拖出扫描的信息
	 * **/
	public String getTuoChuMessage(String txt,String vnb) {

		String messageno = MessageModel.UP_RPANSWER;
		String mt = MessageModel.BDTS;
		SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
		SimpleDateFormat format1 = new SimpleDateFormat("HHmm");
		Date date = new Date();
		String stm = format.format(date);
		List<String> colstr = new ArrayList<String>();

		colstr.add(S.contact(MessageModel.STM, stm));
		colstr.add(S.contact(MessageModel.DID, "CG_OUTHTACM"));
		colstr.add(S.contact(MessageModel.VNB, vnb));
		colstr.add(S.contact(MessageModel.SDT, format1.format(date)));
		colstr.add(S.contact(MessageModel.TXL, S.getStringLen(txt)));
		colstr.add(S.contact(MessageModel.TXT, txt));

		lastScanMessage = getMessage(messageno, mt, colstr);

		return lastScanMessage;
	}
	
	/**
	 * 获取上报的拉/补货信息
	 * **/
	public String getLabuMessage(String txt, String tnb, String fke) {

		String messageno = MessageModel.UP_RPANSWER;
		String mt = MessageModel.BDTS;
		SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
		SimpleDateFormat format1 = new SimpleDateFormat("HHmm");
		Date date = new Date();
		String stm = format.format(date);
		List<String> colstr = new ArrayList<String>();

		colstr.add(S.contact(MessageModel.STM, stm));
		colstr.add(S.contact(MessageModel.strTxtValue[MessageModel.nFKE], fke));
		colstr.add(S.contact(MessageModel.DID, "CG_LDLIST"));
		colstr.add(S.contact(MessageModel.SDT, format1.format(date)));
		colstr.add(S.contact(MessageModel.TXL, S.getStringLen(txt)));
		colstr.add(S.contact(MessageModel.TXT, txt));

		lastScanMessage = getMessage(messageno, mt, colstr);

		return lastScanMessage;
	}

	public void setLastScanMessage(String lastScanMessage) {
		this.lastScanMessage = lastScanMessage;
	}

	public String getLastScanMessage() {
		return lastScanMessage;
	}

	/**
	 * 获取要发送的结束信息
	 */
	public String getTaskMessage(String TNB, String PID,String RMK) {
		String messageno = MessageModel.UP_RPANSWER;
		String mt = MessageModel.TRPT;
		List<String> colstr = new ArrayList<String>();
		colstr.add(S.contact(MessageModel.TNB, TNB));
		colstr.add(S.contact(MessageModel.PID, PID));
		colstr.add(S.contact(MessageModel.TST, "S"));
		if(S.isNotEmpty(RMK))
		{
			colstr.add(S.contact(MessageModel.RMK, RMK));
		}
		String lgt ="";
		String ltt ="";
		float spd = 0;
		GpsInfoBean gpsBean = JavaBeanManager.getInstance().getLastGpsInfo();
		if(gpsBean!=null)
		{
			lgt = gpsBean.getLongitude();
			ltt = gpsBean.getLatitude();
			spd = gpsBean.getGpsSpeed();
		}
		colstr.add(S.contact(MessageModel.LGT,lgt));
		colstr.add(S.contact(MessageModel.LTT,ltt));
		colstr.add(S.contact(MessageModel.SPD,spd));

		String result = getMessage(messageno, mt, colstr);

		if (PID.equals(MessageModel.TRJT) || PID.equals(MessageModel.TACP)) {
			lastAcceptOrRefuseMessage = result;
		}
		lastTaskMessage = result;

		return result;
	}
	
	public String getMonitorRInfo(String _mki,String _content, String _tnb) {
		//按照TRPT消息协议格式发送监控项
		String messageno = MessageModel.UP_RPANSWER;
		String mt = MessageModel.TRPT;
		List<String> colstr = new ArrayList<String>();
		_content = "<!TX<" + S.getCDATA(_content) + ">!>";

		colstr.add(S.contact(MessageModel.TNB, _tnb));
		colstr.add(S.contact(MessageModel.PID, _mki));
		colstr.add(S.contact(MessageModel.SDT, S.getNowTime()));
		colstr.add(S.contact(MessageModel.PEN, _content));
		colstr.add(S.contact(MessageModel.IFSW, "N"));
		lastMonitorMessage = getMessage(messageno, mt, colstr);
		return lastMonitorMessage;
	}
	public String getServiceRInfo(String _mki, String _content, String _tnb)
	{
		String messageno = MessageModel.UP_RPANSWER;
		String mt = MessageModel.TMRP;
		S.getNowTime();
		List<String> colstr = new ArrayList<String>();
		String content = "<!TX<" + S.getCDATA(_content) + ">!>";
		
		colstr.add(S.contact(MessageModel.TNB, _tnb));
		colstr.add(S.contact(MessageModel.MKI, _mki));
		colstr.add(S.contact(MessageModel.SDT, S.getNowTime()));
		colstr.add(S.contact(MessageModel.CNT, content));
		String serviceReportMessage = getMessage(messageno, mt, colstr);
		//保存上报服务标注内容
		String ms = serviceReportMessage.substring(2, 9);
		ServiceLabelUtil.saveReportServiceLabel(ms, _content);
		return serviceReportMessage;
	}
	public String getMonitorHCCInfo(String _sMoniterPid, String _sTnb, String _sSsm) {
		String messageno = MessageModel.UP_RPANSWER;
		String mt = "";
		SimpleDateFormat adfTime = new SimpleDateFormat("yyyyMMddHHmmss");
		Date date = new Date();
		List<String> colstr = new ArrayList<String>();

		//按照TRPT消息协议格式发送监控项
		mt = MessageModel.TRPT;
		colstr.add(S.contact(MessageModel.TNB, _sTnb));
		colstr.add(S.contact(MessageModel.SDT, adfTime.format(date)));
		if (S.isNotEmpty(_sSsm)) {
			colstr.add(S.contact(MessageModel.SSM, _sSsm));
		}
		colstr.add(S.contact(MessageModel.PID, _sMoniterPid));
		if (ParameterModel.HCC_S_SK_YX.equals(_sMoniterPid)) {//需要转发给FOCS系统
			colstr.add(S.contact(MessageModel.RDN, context.getString(R.string.MM_1)));
			colstr.add(S.contact(MessageModel.MTI, "03"));
			colstr.add(S.contact(MessageModel.TXL, S.getStringLen(context.getString(R.string.MM_2))));
			colstr.add(S.contact(MessageModel.TXT, context.getString(R.string.MM_2)));
		}
		
		lastMonitorMessage = getMessage(messageno, mt, colstr);
		return lastMonitorMessage;
	}
	
	//发送HCC监控项的催办信息
	public String getRemindInfo(String _sTnb, String _sFke, String _sRdn, String _sTxt,String _sMid) {
		String messageno = MessageModel.UP_AKANSWER;
		String mt = MessageModel.GWSM;
		SimpleDateFormat adfTime = new SimpleDateFormat("yyyyMMddHHmmss");
		Date date = new Date();
		String stm = adfTime.format(date);
		List<String> colstr = new ArrayList<String>();

		String sEnb = JavaBeanManager.getInstance().getUserinfo().getEnb();
		colstr.add(S.contact(MessageModel.STM, stm));
		colstr.add(S.contact(MessageModel.ENB, sEnb));
		colstr.add(S.contact(MessageModel.TNB, _sTnb));
		colstr.add(S.contact(MessageModel.FKE, _sFke));
		colstr.add(S.contact(MessageModel.MID, _sMid));
		colstr.add(MessageModel.MTI + "03");
		colstr.add(S.contact(MessageModel.RDN, _sRdn));
		colstr.add(S.contact(MessageModel.TST, "S"));
		_sTxt = S.getCDATA(_sTxt);
		colstr.add(MessageModel.TXL + S.getStringLen(_sTxt));
		colstr.add(MessageModel.TXT + _sTxt);
		
		lastRemindMsg = getMessage(messageno, mt, colstr);

		return lastRemindMsg;
	}
	
	//发送锁定机位信息
	public String getTTAQInfo(String lockData, String SR) {
		String messageno = MessageModel.UP_AKANSWER;
		String mt = MessageModel.TTAQ;
		SimpleDateFormat adfTime = new SimpleDateFormat("yyyyMMddHHmmss");
		Date date = new Date();
		String stm = adfTime.format(date);
		List<String> colstr = new ArrayList<String>();
		lockData = S.getCDATA(lockData);
		colstr.add(S.contact(MessageModel.STM, stm));
		colstr.add(S.contact(MessageModel.SUB_FLIGHT_OPE, SR));
		colstr.add(S.contact(MessageModel.TXL, lockData.length()));
		colstr.add(S.contact(MessageModel.TXT, lockData));
		
		lastLockMsg = getMessage(messageno, mt, colstr);

		return lastLockMsg;
	}
	
	public String getLastLockMessage(){
		
		return lastLockMsg;
	}
	public String getLastSubMessage(){
		return lastSubMsg;
	}
	
	public void setLastLockMessage(String msg){
		
		this.lastLockMsg = msg;
	}
	public void setLastSubMessage(String msg){
		
		this.lastSubMsg = msg;
	}
	public String getSendMonitorRInfo() {
		return lastMonitorMessage;
	}
	public void setLastMonitorRInfo(String _sMonitorMsg) {
		this.lastMonitorMessage = _sMonitorMsg;
	}
	public String getRemindInfo() {
		return lastRemindMsg;
	}
	public void setLastRemindInfo(String _sRemindInfo) {
		this.lastRemindMsg = _sRemindInfo;
	}
	
	public String getTRBDMessageInfo(String _sTnb, String _sVnb) {
		String messageno = MessageModel.UP_RPANSWER;
		String mt = MessageModel.TRBD;
		SimpleDateFormat adfTime = new SimpleDateFormat("yyyyMMddHHmmss");
		Date date = new Date();
		String stm = adfTime.format(date);
		List<String> colstr = new ArrayList<String>();

		colstr.add(S.contact(MessageModel.STM, stm));
		colstr.add(S.contact(MessageModel.TNB, _sTnb));
		colstr.add(S.contact(MessageModel.VNB, _sVnb));
		if(S.isNotEmpty(_sVnb))
		{
			colstr.add(S.contact(MessageModel.TST, "Y"));
		}
		else
		{
			colstr.add(S.contact(MessageModel.TST, "N"));
		}
		lastTRBDMessage = getMessage(messageno, mt, colstr);

		return lastTRBDMessage;
	}
	public String getLastSendTRBDInfo() {
		return lastTRBDMessage;
	}
	public void setLastSendTRBDInfo(String _sTRBDMsg) {
		this.lastTRBDMessage = _sTRBDMsg;
	}
	
	public String getTaskProcStatusMsg() {
		return lastTaskMessage;
	}

	public String getLastLogoutMessage() {
		return lastLogoutMessage;
	}

	public String getLastLogonMessage() {
		return lastLogonMessage;
	}
	public String getLastRecLogonMessge(){
		return lastRecLogonMessage;
	}
	public String getlastAcceptOrRefuseMessage() {
		return lastAcceptOrRefuseMessage;
	}

	public String getlastSGOCMessage() {
		return lastSGOCMessage;
	}

	public String getlastGroupMessage() {
		return lastGroupMessage;
	}

	public void setLastSendGWSMMessage(String sGWSM) {
		this.lastGWSMMessage = sGWSM;
	}
	public String getLastSendGWSMMessage() {
		return lastGWSMMessage;
	}

	public String getLastSendBDWIMessage() {
		return lastBDWIMessage;
	}

	public void setLastSendMessage(String _lastGWSMMessage) {
		this.lastGWSMMessage = _lastGWSMMessage;
	}
	
	public String getLastSearchFlightMessage() {
		return lastSearchFlightMessage;
	}

	public void setLastSearchFlightMessage(String lastSearchFlightMessage) {
		this.lastSearchFlightMessage = lastSearchFlightMessage;
	}

	public String getLastJobWorkingPhraseMessage() {
		return lastJobWorkingPhraseMessage;
	}

	public void setLastJobWorkingPhraseMessage(
			String lastJobWorkingPhraseMessage) {
		this.lastJobWorkingPhraseMessage = lastJobWorkingPhraseMessage;
	}

	public String getLastTaskWorkingPhraseMessage() {
		return lastTaskWorkingPhraseMessage;
	}

	public void setLastTaskWorkingPhraseMessage(
			String lastTaskWorkingPhraseMessage) {
		this.lastTaskWorkingPhraseMessage = lastTaskWorkingPhraseMessage;
	}

	public void setLastSGOCMessage(String lastSGOCMessage) {
		this.lastSGOCMessage = lastSGOCMessage;
	}

	public void setLastIQRYMessage(String lastIQRYMessage) {
		this.lastIQRYMessage = lastIQRYMessage;
	}

	public void setLastLogonOutMessage(String lastLogonOutMessage) {
		this.lastLogoutMessage = lastLogonOutMessage;
	}

	public void setLastLogonMessage(String lastLogonMessage) {
		this.lastLogonMessage = lastLogonMessage;
	}

	public void setLastRecLogonMessge(String lastRecLogonMessage){
		this.lastRecLogonMessage = lastRecLogonMessage;
	}
	
	public void setLastSendQQRYMsg(String _lastQQRYMsg) {
		this.lastQQRYMessage = _lastQQRYMsg;
	}
	public String getLastSendQQRYMsg() {
		return lastQQRYMessage;
	}
	/**
	 * 获取IQRY信息
	 * 
	 * @return
	 */
	public String getLastIQRYMessage() {
		return lastIQRYMessage;
	}

	/**
	 * 获取Gps信息
	 * 
	 * @return
	 */
	public String getLastGpsMessage() {
		return lastGpsMessage;
	}

	public String getLastApplyFlightTaskMessage() {
		return lastApplyFlightTaskMessage;
	}

	public void setLastApplyFlightTaskMessage(String lastApplyFlightTaskMessage) {
		this.lastApplyFlightTaskMessage = lastApplyFlightTaskMessage;
	}
	//add by huzedong 航班订阅
	public String getHBDYInfo(String FKE, String fln, String Send) {
		String messageno = MessageModel.UP_AKANSWER;
		String mt = MessageModel.HBDY;
		SimpleDateFormat adfTime = new SimpleDateFormat("yyyyMMddHHmmss");
		Date date = new Date();
		String stm = adfTime.format(date);
		List<String> colstr = new ArrayList<String>();

		colstr.add(S.contact(MessageModel.STM, stm));
		colstr.add(S.contact(MessageModel.SUB_FLIGHT_FKE, FKE));
		colstr.add(S.contact(MessageModel.SUB_FLIGHT_FLN, fln));
		colstr.add(S.contact(MessageModel.SUB_FLIGHT_OPE, Send));
		lastSubMsg = getMessage(messageno, mt, colstr);
		return lastSubMsg;
	}
	
	/*
	 * 提供进程节点的备注信息控制，只存最新备注
	 */
	public String getLastRMK() {
		return lastRMK;
	}
	
	public void setLastRMK(String rmk) {
		lastRMK = rmk;
	}

}
